﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CLEXA.DALTests
{
    public static class Helper
    {
        public static readonly string CONNECTION_STRING = "Data Source=tcp:twwec9cw6n.database.windows.net,1433;Initial Catalog=clexa_test;Persist Security Info=True;User ID=clexa_user;Password = PASw0ord!;Pooling=False";

        public static void ClearData()
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendLine("delete from clexa.tb_database");
            builder.AppendLine("delete from clexa.tb_user");

            using (SqlConnection conn = new SqlConnection(CONNECTION_STRING))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand(builder.ToString(), conn))
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.ExecuteNonQuery();
                }
            }
        }

        public static string NextString(this Random random, int length)
        {
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < length; i++)
            {
                builder.Append((char)('a' + random.Next((int)('z' - 'a' + 1))));
            }
            return builder.ToString();
        }

        public static void PrintList<T>(this IEnumerable<T> collection)
        {
            foreach (T item in collection)
            {
                Console.WriteLine(item);
            }
        }
    }
}
